﻿using DataAccess;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;

namespace MyPetHub.Filters
{
    public class AdminHomeActionFilterAttribute : Attribute, IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext context)
        {
            SysUser? mm = JsonConvert.DeserializeObject<SysUser>(context.HttpContext.Session.GetString("SysUser"));

            var viewData = (context.Controller as Controller).ViewData;
            viewData["nickname"] = mm.nickname ?? mm.account;
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
        }
    }
}
